enum UserRole {
  admin,
  main,
  part,
  org,
  normal,
  other,
  apply,
  repair,
  reimburse,
  business,
  weekend,
}

class UiasRoleList {
  String? roleId;
  String? roleName;
  String? roleCode;
  String? sourceId;
  String? sourceType;
  int? roleType;

  UserRole get role {
    switch (roleCode) {
      case 'identity_admin':
        return UserRole.admin;
      case 'identity_main_leader':
        return UserRole.main;
      case 'identity_part_leader':
        return UserRole.part;
      case 'identity_leader':
        return UserRole.org;
      case 'identity_staff':
        return UserRole.normal;
      case 'identity_reimburse_appr':
        return UserRole.reimburse;
      case 'identity_item_apply_appr':
        return UserRole.apply;
      case 'identity_repair_appr':
        return UserRole.repair;
      case 'identity_business_trip_appr':
        return UserRole.business;
      case 'identity_weekend_duty':
        return UserRole.weekend;
      default:
        return UserRole.other;
    }
  }

  UiasRoleList({
    this.roleId,
    this.roleName,
    this.roleCode,
    this.sourceId,
    this.sourceType,
    this.roleType,
  });

  factory UiasRoleList.fromJson(Map<String, dynamic> json) => UiasRoleList(
        roleId: json['roleId'] as String?,
        roleName: json['roleName'] as String?,
        roleCode: json['roleCode'] as String?,
        sourceId: json['sourceId'] as String?,
        sourceType: json['sourceType'] as String?,
        roleType: json['roleType'] as int?,
      );

  Map<String, dynamic> toJson() => {
        'roleId': roleId,
        'roleName': roleName,
        'roleCode': roleCode,
        'sourceId': sourceId,
        'sourceType': sourceType,
        'roleType': roleType,
      };
}
